<?php
class BrandController extends Controller{
	private $model;
	public function __construct(){
		parent::__construct();
		$this->model=K("Brand");
	}
	public function index(){
//		获得所有数据
        $bData=$this->model->all();
		$this->assign("bData",$bData);
		$this->display();
	}
	public function edit(){
//		获得地址栏传的id
        $id=$_GET['id'];
		if(IS_POST){
			$id=$_POST['id'];
		    if(!$this->model->updateData($id)){
		    	$this->error($this->model->error);
		    }
			$this->success("修改成功");
		}
//		获得旧数据
        $oldData=$this->model->where("id='{$id}'")->find();
		
		$this->assign("oldData",$oldData);
		$this->display();
		
	}
	public function del(){
		$id=$_GET['id'];
		if(!$this->model->where("id='{$id}'")->delete()){
			$this->error($this->model->error);
		};
		$this->success("删除成功");
		
		
	}
	public function add(){
		if(IS_POST){
		
			if(!$this->model->addData()){
				$this->error($this->model->error);
			}
			$this->success("添加成功");
			
		}
		$this->display();
	}
}
 ?>